<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
</head>
<body class="no-skin">
	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
							<form action="hospital/${action}.do" name="hospitalForm"
								id="hospitalForm" method="post">
								<input type="hidden" name="HOSPITAL_ID" id="hospital_id"
									value="${pd.HOSPITAL_ID}" /> <input type="hidden"
									name="RCDSTS" id="rcdsts" value="${pd.RCDSTS}" />
								<div id="zhongxin" style="padding-top: 13px;">
									<table id="table_report"
										class="table table-striped table-bordered table-hover">

										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">医院名称:</td>
											<td><input type="text" name="HOSPITALNAME"
												id="hospitalname" value="${pd.HOSPITALNAME }"
												maxlength="100" placeholder="这里输入医院名称" title="医院名称"
												style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">选择级别:</td>
											<td><select id="level" name="LEVEL">
													<option value=""></option>
													<c:forEach items="${hospitalLevel}" var="item">
														<option value="${item.DICTIONARIES_ID}"
															<c:if test="${item.DICTIONARIES_ID==pd.LEVEL}">selected="selected"</c:if>>${item.NAME}</option>
													</c:forEach>
											</select></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">选择地区:</td>
											<td><select id="address1" name="ADDRESS1">
													<option value=""></option>
													<c:forEach items="${DictionariesList}" var="item">
														<option value="${item.DICTIONARIES_ID}"
															<c:if test="${item.DICTIONARIES_ID==pd.ADDRESS1}">selected="selected"</c:if>>${item.NAME}</option>
													</c:forEach>
											</select> <select id="address2" name="ADDRESS2">
											</select> <select id="address3" name="ADDRESS3">
											</select></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">详细地址:</td>
											<td><input type="text" name="ADDRESS" id="address"
												value="${pd.ADDRESS}" maxlength="255" placeholder="输入详细地址"
												title="详细地址" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">邮编:</td>
											<td><input type="number" name="POSTALCODE"
												id="postalcode" value="${pd.POSTALCODE}" maxlength="15"
												placeholder="输入邮编" title="输入邮编" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">传真:</td>
											<td><input type="number" name="FAX" id="fax"
												value="${pd.FAX}" maxlength="30" placeholder="这里输入传真"
												title="传真" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">联系电话:</td>
											<td><input type="number" name="TELEPHONE" id="telephone"
												value="${pd.TELEPHONE}" maxlength="30"
												placeholder="这里输入联系电话" title="联系电话" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">医院详细描述:</td>
											<td><textarea name="DESCRIPTION" id="description"
													multiple="multiple" height="200px" placeholder="这里输入详细描述"
													title="详细描述" style="width: 98%;">${pd.DESCRIPTION}</textarea></td>
										</tr>
										<tr>
											<td
												style="width: 79px; text-align: right; padding-top: 13px;">备注:</td>
											<td><input type="text" name="REMARK" id="remark"
												value="${pd.REMARK}" placeholder="这里输入备注" maxlength="64"
												title="备注" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td style="text-align: center;" colspan="10"><a
												class="btn btn-mini btn-primary" onclick="save();">保存</a> <a
												class="btn btn-mini btn-danger"
												onclick="top.Dialog.close();">取消</a></td>
										</tr>
									</table>
								</div>
								<div id="zhongxin2" class="center" style="display: none">
									<br /> <br /> <br /> <br /> <img
										src="static/images/jiazai.gif" /><br />
									<h4 class="lighter block green"></h4>
								</div>
							</form>
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->
	</div>
	<!-- /.main-container -->
	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../index/foot.jsp"%>
	<!-- ace scripts -->
	<script src="static/ace/js/ace/ace.js"></script>
	<!-- inline scripts related to this page -->
	<!-- 下拉框 -->
	<script src="static/ace/js/chosen.jquery.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
	$(top.hangge());
	$(document).ready(function() {
		if ($("#hospital_id").val() != "") {
			$("#hospitalname").attr("readonly", "readonly");
			$("#hospitalname").css("color", "gray");
		}
	});
	//保存
	function save() {

		if ($("#hospitalname").val() == ""
				|| $("#hospitalname").val() == "此医院名称已存在!") {
			$("#hospitalname").tips({
				side : 3,
				msg : '输入医院名称',
				bg : '#AE81FF',
				time : 2
			});
			$("#hospitalname").focus();
			$("#hospitalname").val('');
			$("#hospitalname").css("background-color", "white");
			return false;
		} else {
			$("#hospitalname").val(jQuery.trim($('#hospitalname').val()));
		}

		if ($("#address").val() == "") {
			$("#address").tips({
				side : 3,
				msg : '输入地址',
				bg : '#AE81FF',
				time : 3
			});
			$("#address").focus();
			return false;
		} else {
			$("#address").val($.trim($("#address").val()));
		}

		if ($("#discription").val() == "") {
			$("#discription").tips({
				side : 3,
				msg : '请输入医院描述信息',
				bg : '#AE81FF',
				time : 3
			});
			$("#discription").focus();
			return false;
		}
		var myreg = /^(((13[0-9]{1})|159)+\d{8})$/;
		if ($("#telephone").val() == "") {

			$("#telephone").tips({
				side : 3,
				msg : '输入手机号',
				bg : '#AE81FF',
				time : 3
			});
			$("#telephone").focus();
			return false;
		} else if ($("#telephone").val().length != 11
				&& !myreg.test($("#telephone").val())) {
			$("#telephone").tips({
				side : 3,
				msg : '手机号格式不正确',
				bg : '#AE81FF',
				time : 3
			});
			$("#telephone").focus();
			return false;
		}

		$("#hospitalForm").submit();
		$("#zhongxin").hide();
		$("#zhongxin2").show();

	}
	function ismail(mail) {
		return (new RegExp(
				/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/)
				.test(mail));
	}

	$(function() {
		//下拉框
		if (!ace.vars['touch']) {
			$('.chosen-select').chosen({
				allow_single_deselect : true
			});
			$(window).off('resize.chosen').on('resize.chosen', function() {
				$('.chosen-select').each(function() {
					var $this = $(this);
					$this.next().css({
						'width' : $this.parent().width()
					});
				});
			}).trigger('resize.chosen');
			$(document).on('settings.ace.chosen',
					function(e, event_name, event_val) {
						if (event_name != 'sidebar_collapsed')
							return;
						$('.chosen-select').each(function() {
							var $this = $(this);
							$this.next().css({
								'width' : $this.parent().width()
							});
						});
					});
			$('#chosen-multiple-style .btn').on('click', function(e) {
				var target = $(this).find('input[type=radio]');
				var which = parseInt(target.val());
				if (which == 2)
					$('#form-field-select-4').addClass('tag-input-style');
				else
					$('#form-field-select-4').removeClass('tag-input-style');
			});
		}

		$("#address1").change(

				function() {
					$.post("dictionaries/listSubDictByParentId.do", {
						"parent_id" : $(this).val()
					},
							function(result) {
								if (result != undefined) {
									$("#address2").empty();
									$("#address2").append(
											"<option value=''></option>");
									for (var i = 0; i < result.length; i++) {
										$("#address2").append(
												"<option value="+result[i].dictionaries_ID+">"
														+ result[i].name
														+ "</option>");
									}
								}
							}, "json");

				});

		$("#address2").change(

				function() {
					$.post("dictionaries/listSubDictByParentId.do", {
						"parent_id" : $(this).val()
					},
							function(result) {
								if (result != undefined) {
									$("#address3").empty();
									$("#address3").append(
											"<option value=''></option>");
									for (var i = 0; i < result.length; i++) {
										$("#address3").append(
												"<option value="+result[i].dictionaries_ID+">"
														+ result[i].name
														+ "</option>");
									}
								}
							}, "json");

				});

		if ("${pd.HOSPITAL_ID}" != null && "${pd.HOSPITAL_ID}" != "") { //修改

			if ($("#address1").val() != null && $("#address1").val() != "") {

				$.post("dictionaries/listSubDictByParentId.do", {
					"parent_id" : $("#address1").val()
				}, function(result) {
					if (result != undefined) {
						
						$("#address2").empty();
						$("#address2").append("<option value=''></option>");
						var optionitme = "";
						for (var i = 0; i < result.length; i++) {
							var varselecte = "";
							if ("${pd.ADDRESS2}" == result[i].dictionaries_ID) {
								varselecte = ' selected="selected"';
							}
							
							$("#address2").append(
									"<option value="+result[i].dictionaries_ID+varselecte+">"
											+ result[i].name + "</option>");
						}
						
						
						$.post("dictionaries/listSubDictByParentId.do", {
							"parent_id" : $("#address2").val()
						}, function(result) {
							if (result != undefined) {
								
								$("#address3").empty();
								$("#address3").append("<option value=''></option>");
								var optionitme = "";
								for (var i = 0; i < result.length; i++) {
									var varselecte = "";
									if ("${pd.ADDRESS3}" == result[i].dictionaries_ID) {
										varselecte = ' selected="selected"';
									}
									
									$("#address3").append(
											"<option value="+result[i].dictionaries_ID+varselecte+">"
													+ result[i].name + "</option>");
								}
							}
						}, "json");
						
					}
				}, "json");

			}

		}

	});
</script>
</html>